package com.ourteam.education.api;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.ourteam.education.dao.TeacherCampusRelateDAOFactory;
import com.ourteam.education.dao.TeacherCampusRelateDAOQueryBean;
import com.ourteam.education.dao.TeacherDAOQueryBean;
import com.ourteam.education.domain.TeacherBean;
import com.ourteam.frame.web.AbstractSearchModel;

public class TeacherSearchBean extends AbstractSearchModel<TeacherDAOQueryBean> {

	private String teacherName;

	private String contactPhone;

	private Long[] campusIdList;

	private String[] status;

	public String getTeacherName() {
		return teacherName;
	}

	public void setTeacherName(String teacherName) {
		this.teacherName = teacherName;
	}

	public String getContactPhone() {
		return contactPhone;
	}

	public void setContactPhone(String contactPhone) {
		this.contactPhone = contactPhone;
	}

	public String[] getStatus() {
		return status;
	}

	public void setStatus(String[] status) {
		this.status = status;
	}

	public Long[] getCampusIdList() {
		return campusIdList;
	}

	public void setCampusIdList(Long[] campusIdList) {
		this.campusIdList = campusIdList;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return TeacherBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(TeacherDAOQueryBean queryBean) throws Exception {

		TeacherDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (StringUtils.isNoneBlank(this.teacherName)) {
			criteria.andTeacherNameLike(teacherName);
		}

		if (StringUtils.isNoneBlank(this.contactPhone)) {
			criteria.andContactPhoneLike(contactPhone);
		}

		if (ArrayUtils.isNotEmpty(this.status)) {
			criteria.andStatusIn(this.status);
		}
		
		if(ArrayUtils.isNotEmpty(this.campusIdList)) {
			
			TeacherCampusRelateDAOQueryBean relateQueryBean = new TeacherCampusRelateDAOQueryBean();
			
			relateQueryBean.setDistinct(true);
			
			relateQueryBean.createCriteria().andCampusIdIn(campusIdList);
			
			relateQueryBean.addTeacherIdSelectProperty();
			
			criteria.andIdIn(relateQueryBean, TeacherCampusRelateDAOFactory.getTeacherCampusRelateDAO());
			
		}

	}

}
